/* EdgeListNode.java */

package graph;

import list.*;

/**
 * This class represents a node in an Edge List. The main
 * difference between this node and most others is that it
 * also contains a pointer to its partner edge. Methods,
 * especially remove are aware of this special EdgeListNode.
 */
class EdgeListNode extends DListNode {

  /**
   *  EdgeListNode() constructor.
   *  @param i the item to store in the node.
   *  @param l the list this node is in.
   *  @param p the node previous to this node.
   *  @param n the node following this node.
   */
  EdgeListNode(Object i, DList l, DListNode p, DListNode n) {
    super(i, l, p, n);
  }

  /** 
   * Partner is an EdgeListNode identical to this, but in another
   * Edge list. 
   */
  EdgeListNode partner = null;
    /** 
     * Removes the node from the list. If the list has a partner that
     * list is also removed from the list
     */
  public void remove() throws InvalidNodeException{
    if (partner != null && partner != this) {
      partner.partner = null;
      partner.remove();
      partner = null;
    }
    super.remove();
  }
  
  /**
   * Sets the partner of this node. No error checking to see if the
     * node is really a partner.
     */
  public void setPartner(EdgeListNode partner) {
    this.partner = partner;
    partner.partner = this;
  }
}
